package com.easidea.tim.dao.finance;

import java.util.Date;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springside.core.dao.extend.HibernateEntityExtendDao;

import com.easidea.tim.entity.finance.ShouldPay;
import com.easidea.tim.entity.finance.ShouldPaySummary;
import com.easidea.tim.entity.purchase.PurchaseOrder;


public class ShouldPayDao extends HibernateEntityExtendDao<ShouldPay> {
    /**
     * 根据采购订单号查询应付款
     * @param orderId
     * @return
     */
	public ShouldPay getShouldPayByOrderId(long orderId) {
  	  Criteria ca = this.createUnDeletedCriteria();
	  ca.add(Restrictions.eq("order.id", orderId)); 
	  return (ShouldPay) ca.uniqueResult();
    }


	/**
	 * @author Harrison
	 * @param order
	 * @param summary
	 */
	public  void saveOrUpdateShouldPay(PurchaseOrder order, ShouldPaySummary summary, Double currentAmount ) {
		  ShouldPay pay = new ShouldPay();	  
		  pay.setBillAmount(currentAmount);
		  pay.setBillDate(new Date());
		  pay.setOrder(order);
		  pay.setShouldPaySummary(summary);
		  getHibernateTemplate().save(pay);
	}

}
